package com.qin.springbootdemo.dao;

import com.qin.springbootdemo.entity.favoriteEntity;
import org.apache.tomcat.jni.Address;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Leisure
 * create 2022 2022/6/18 13:42
 **/
@Repository
public class favoriteDao {
    @Autowired
    private MongoTemplate mongoTemplate;

    //查找收藏
    public List<favoriteEntity> findFavoriteAll(){
        List<favoriteEntity> favorite = mongoTemplate.findAll(favoriteEntity.class);
        return favorite;
    }

    //删除收藏
    public void delFavorite(String id) {
        // TODO Auto-generated method stub
        // Query query = new Query(Criteria.where("_id").is(id));
        org.springframework.data.mongodb.core.query.Query query = new Query(Criteria.where("_id").is(id));
        mongoTemplate.remove(query, favoriteEntity.class);
    }
    //加入收藏
    public Address insertFavorite(favoriteEntity favorite) {
        // TODO Auto-generated method stub
        this.mongoTemplate.save(favorite, "favorite");
        return null;
    }
}
